//=============================================================================
//D Shows my simple inline cast scheme for booleans
//
// Used as an example for the C++ standards committee on why sometimes
// templates are too complex and a simple easy to understand solution is better
//
// ----------------------------------------------------------------------------
// Copyright 2013 Delcam plc., Birmingham, UK
// ----------------------------------------------------------------------------
//
// History.
// DICC   Who When     What   
// ------ --- -------- --------------------------------------------------------
// 999999 CLH 18/06/13 Written.
//-----------------------------------------------------------------------------
#include "stdafx.h"

#include "cpp/cppCasts.h"

// additional includes from 'cpp' library
// includes from PowerINSPECT libraries
// includes from Delcam libraries
#include "utils/ut_assert.h"   // Use assertions!
// includes from other libraries
// system includes

// types: classes, enums, typedefs

// variables: consts, statics, exported variables (declared extern elsewhere)
// local forward function declarations

#ifdef _DEBUG
//#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

class C {
public:
  C() { m_c = 3;}
  int m_c;
};

class B {
public:
  B() { m_b = 2;}
  virtual ~B() {}
  int m_b;
};

class A : public C, public B
{
public:
  A() { m_a = 1;}
  int m_a;
};

class D {
public:
  D() { m_d = 4;}
  virtual ~D() {}
  int m_d;
};

class E : public D, public B
{
public:
  E() { m_e = 5;}
  int m_e;
};


//=============================================================================
cppCasts::cppCasts()
//
//D Default constructor.
//
// History.
// DICC   Who When     What   
// ------ --- -------- --------------------------------------------------------
// 999999 CLH 18/06/13 Written.
//-----------------------------------------------------------------------------
{
  UT_CHECKVALID_CLASS;
}

//=============================================================================
cppCasts::~cppCasts()
//
//D Destructor.
//
// History.
// DICC   Who When     What   
// ------ --- -------- --------------------------------------------------------
// 999999 CLH 18/06/13 Written.
//-----------------------------------------------------------------------------
{
  UT_CHECKVALID_CLASS;
}

//=============================================================================
void cppCasts::run()
//
//D Details of the function.
//
// History.
// DICC   Who When     What   
// ------ --- -------- --------------------------------------------------------
// 999999 CLH 18/06/13 Written.
//-----------------------------------------------------------------------------
{
  UT_CHECKVALID_CLASS;
  VARIANT_BOOL v = to_VARIANT_BOOL(true);


  BOOL bi = TRUE;

  v = to_VARIANT_BOOL(bi);

  v = to_VARIANT_BOOL(VARIANT_TRUE);

  bool b = to_bool(TRUE);

  int x = true;

  if (bool_equal(VARIANT_TRUE, true)) {
    printf("pass 1\n");
  }

  if (!bool_equal(VARIANT_FALSE, true)) {
    printf("pass 1\n");
  }

  B* bb = new E;
  E* es = static_cast<E*>(bb);
  A* as = static_cast<A*>(bb);

  E* ed = dynamic_cast<E*>(bb);
  A* ad = dynamic_cast<A*>(bb);


  printf("A = %d\n", as->m_a);
  printf("E = %d\n", es->m_e);

}
